<template>
  <div class="color-selection">
    <span class="label">{{ label }}</span>
    <div class="picker">
      <a @click.prevent="reset">重置</a>
      <input type="color" v-model="value" />
    </div>
  </div>
</template>

<script>
  export default {
    name: 'ColorSelection',
    props: {
      label: {
        type: String,
        default: '背景颜色'
      },
      color: {
        type: String,
        default: '#FFEFB8'
      }
    },
    computed: {
      value: {
        get () {
          return this.color
        },
        set (val) {
          this.$emit('update:color', val)
        }
      }
    },
    data () {
      return {
        defaultValue: this.color
      }
    },
    methods: {
      reset () {
        this.value = this.defaultValue
      }
    }
  }
</script>

<style lang="less" scoped>
  .color-selection {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    .label {
      width: 56px;
    }
    .picker {
      a {
        margin-right: 5px;
      }
    }
  }
</style>
